package ru.spb.osll.myfit.examples;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ru.spb.osll.myfit.fixtures.base.OneLineFixture;

public class WaitForFixture extends OneLineFixture {
	
  public static final Pattern INTERVAL_MINUTE_PATTERN = Pattern.compile("([0-9]+)\\s+(minute)");
  public static final Pattern INTERVAL_SECOND_PATTERN = Pattern.compile("([0-9]+)\\s+(second)");
  
  public boolean waitFor(String interval) {
    Matcher matcher = INTERVAL_MINUTE_PATTERN.matcher(interval);
    if(matcher.matches()){
      String number = matcher.group(1);
      Long minutes = Long.valueOf(number);
      try {
        Thread.sleep(minutes*60000);
      } catch (InterruptedException e) {
        
      }
      return true;
    }
    matcher = INTERVAL_SECOND_PATTERN.matcher(interval);
    if(matcher.matches()){
      String number = matcher.group(1);
      Long minutes = Long.valueOf(number);
      try {
        Thread.sleep(minutes*1000);
      } catch (InterruptedException e) {
        
      }
      return true;
    }
    
    return true;
  }

	public static String[] getTestTableTemplates() {
		return new String[] { "|wait for|1 hour|" };
	}
}
